<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>document</title>
  <style type="text/css">
  *{margin: 0;padding: 0;}
  
  </style>
  <script type="text/javascript">
    window.onload = function (){
      var Btn = document.getElementsByTagName('input')[0];
      var Btn1 = document.getElementsByTagName('input')[1];
      var r = 0;
      var g = 0;
      var b = 0;
      var Body = document.body;
      var timer = null;
      function fun(){
        r = Math.round(Math.random() * 255);
        g = Math.round(Math.random() * 255);
        b = Math.round(Math.random() * 255);
        Body.style.background = 'rgb('+ r + ',' + g + ',' + b +')';
      }
      Btn.onclick = function (){
        clearInterval(timer);
        timer = setInterval(fun,1000);
      }
       Btn1.onclick = function (){
        clearInterval(timer);
      }
    }
  </script>
</head>
<body>
  <input type="button" value="更换颜色">
  <input type="button" value="停止">
</body>
</html>